package com.xgc.book.bookserver.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xgc.book.bookserver.bean.NoticeBean;
import com.xgc.book.bookserver.mapper.NoticeMapper;
import com.xgc.book.bookserver.service.NoticeService;
import com.xgc.book.bookserver.util.ResultJson;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 系统公告表 服务实现类
 * </p>
 *
 * @author wrz
 * @since 2023-11-20
 */
@Service
@Transactional
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, NoticeBean> implements NoticeService {

    @Override
    public ResultJson getPage(int page, int limit, NoticeBean noticeBean) {
        IPage<NoticeBean> iPage = this.page(new Page<>(page, limit),
                new QueryWrapper<NoticeBean>()
                        .eq(noticeBean.getStatus() != null, "status", noticeBean.getStatus())
                        .gt(noticeBean.getExpires() != null, "expires", noticeBean.getExpires())
                        .orderByDesc("expires"));
        return ResultJson.ok(iPage);
    }
}
